package study.day7;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class T3 {
    //字节流写入
    public static void main(String[] args) {
        FileOutputStream fos = null;
        try {
            fos=new FileOutputStream("C:\\Users\\DELL\\IdeaProjects\\file\\2.txt");
            //写入操作
            String word="中国";
            //将字符串转换成字符数组
            byte[] bytes=word.getBytes();
            fos.write(bytes);//自动调用flush
            System.out.println("写入成功");
        } catch (FileNotFoundException e) {
            System.out.println("File not found");
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
